<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>注册新用户</title>
</head>
<body>
	<div>
		<a href="${pageContext.request.contextPath}/toLogin">回登录页面</a>
	</div>
	<form action="${pageContext.request.contextPath}/user/insert" method="post">
		<input type="text" name="username" placeholder="请输入用户名" required="required"><span style="color: red;">${uInfo }</span><br>
		<input type="password" name="password" placeholder="请输入密码" required="required"><span style="color: yellow;">${pInfo }</span><br>
		<input type="submit" value="注册">
	</form>
</body>
<script type="text/javascript" src="${pageContext.request.contextPath }/statics/js/jquery-3.5.1.js"></script>
<script type="text/javascript">
 	$("input:first").blur(function(){
		//用户名正则，4到16位（字母，数字，下划线，减号）
		var uPattern = /^[a-zA-Z0-9_-]{4,16}$/;

		var username=$("input:first").val();
		if(uPattern.test(username)==false){
			$("span:first").html("用户名只能输入长度为4-16（字母，数字，下划线，减号）");
			return false;
		}
		$.ajax({
			type:"post",
			url:"${pageContext.request.contextPath}/user/selectByUsername",
			data:{"username":username},
			success:function(result){
				if(result===1){
					$("span:first").html("用户名已存在(后端)");
				} else{
					$("span:first").html("打个勾（后端）");
				}
			}
		});
	});

	$("input:eq(1)").blur(function(){
		//密码强度正则，最少6位，包括至少1个大写字母，1个小写字母，1个数字，1个特殊字符
		//var pPattern = /^.*(?=.{6,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/;
		//密码由英文字母和数字组成的4-10位字符
		var pPattern=/^[a-zA-Z0-9]{4,10}$/;  

		var password=$("input:eq(1)").val();
		if(pPattern.test(password)==false){
			$("span:eq(1)").html("密码只能输入由字母和数字组成的4-10位字符");
		}else{
			$("span:eq(1)").html("打个勾");
		}
	}); 
</script>
</html>